const qr = require("qr-image");
const http = require('http');
let server = http.createServer(async function (req, res) {
    let data = []
    req.on('data', chunk => {
        data.push(chunk)  // 将接收到的数据暂时保存起来
    })
    req.on('end', () => {
        try{
            let params = JSON.parse(data) // 数据传输完，打印数据的内容
            console.log(`params:===>>> ${JSON.stringify(params)}`)
            let img = qr.image(params.data, {
                size: 10
            });
            res.writeHead(200, {'Content-Type': 'image/png'});
            img.pipe(res);
        }catch (e) {
            res.end('error')
        }

    })

});
server.listen(3000);
console.log('qr server start ...')